package com.ejuornal.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.Category;
import com.ejuornal.dao.CategoryDao;
import com.ejuornal.service.CategoryService;

@Component("categoryService")
public class CategoryServiceImpl implements CategoryService {
	private CategoryDao categoryDao;

	public void add(Category category) {
		String sql = "insert into t_category(categoryId,name,introduce,enName) values (?,?,?,?)";
		categoryDao.add(sql,
				new Object[] { 
					null,
					category.getName(), 
					category.getIntroduce(),
					category.getEnName() 
				});
	}

	public void delete(int... categoryId) {
		String sql = "delete from t_category where categoryId = ?";
		categoryDao.batchDelete(sql, categoryId);
	}

	public void update(int categoryId, Category category) {
		String sql = "update t_category set name = ?,introduce = ?,enName = ? where categoryId = ?";
		categoryDao.update(sql,
				new Object[] { 
					category.getName(), 
					category.getIntroduce(),
					category.getEnName(), 
					categoryId 
				});
	}

	public List<Category> top(int count) {
		List<Category> list = categoryDao.top(count);
		return list;
	}
	
	public List<Category> findAll() {
		List<Category> list = categoryDao.findAll();
		return list;
	}
	
	public Category findById(int categoryId) {
		return categoryDao.findById(categoryId);
	}

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	@Resource(name = "categoryDao")
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

}
